public class ThreadDemo2 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            //currentThread() 方法是获取当前线程的实例，即这里的t
            while(!Thread.currentThread().isInterrupted()) {
                System.out.println("ThreadDemo");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("执行完毕");
        });
        t.start();
        Thread.sleep(5000);
        System.out.println("让线程结束");
        t.interrupt();
    }
}
